/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utils;

import GUI.Admin.AdminPlaceDetailsDialog;
import javax.swing.JButton;
import javax.swing.JFrame;
import main.MainFormApp;
import pojo.Chongoi;

/**
 *
 * @author Hnmtuan
 */
public class PlaceButton extends JButton {

    private Chongoi _ownedPlace;
    private AdminPlaceDetailsDialog _placeDetails;
    private JFrame _mainFrame;
//    private ActionMap _rsActionMap;
    public static final int DEFAULT_WIDTH = 55;
    public static final int DEFAULT_HEIGHT = 23;

    public PlaceButton(String btnName, Chongoi passPlace) {
        super(btnName);
//        _rsActionMap = Application.getInstance(main.MainFormApp.class).getContext().getActionMap(getClass(), this);
        _mainFrame = MainFormApp.getApplication().getMainFrame();
        _ownedPlace = passPlace;
        String label = (_ownedPlace != null) ? String.format("P%d", _ownedPlace.getViTriChoNgoi()) : btnName;
        setText(label);
//        setAction(_rsActionMap.get("showPlaces"));
        if (_ownedPlace != null) {
            addActionListener(new java.awt.event.ActionListener() {

                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    try {
                        _placeDetails = new AdminPlaceDetailsDialog(null, true, _ownedPlace);
                        MainFormApp.getApplication().show(_placeDetails);
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            });
        }
    }

    public Chongoi getOwnedPlace() {
        return _ownedPlace;
    }

    public void setOwnedPlace(Chongoi _ownedPlace) {
        this._ownedPlace = _ownedPlace;
    }
}
